package com.tbvtc.agriculturalcreditchainserver2025.utils;

public enum CropType {
    CITRUS("1", "柑橘"),
    WEED("2", "杂草"),
    APPLE("123", "苹果"),
    GRAPE("127", "葡萄"),
    WHEAT("131", "小麦"),
    RICE("132", "水稻"),
    FALL_ARMYWORM("142", "草地贪夜蛾"),
    INSECT_BODY("143", "虫体");

    private final String code;
    private final String name;

    CropType(String code, String name) {
        this.code = code;
        this.name = name;
    }

    // 获取枚举值对应的编码
    public String getCode() {
        return code;
    }

    // 获取中文描述
    public String getName() {
        return name;
    }

    // 通过编码反向查找枚举值
    public static CropType parse(String code) {
        for (CropType type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的作物编码: " + code);
    }
}